/**
 * created by 小卷毛, 2021-09-10
 * Copyright (c) 2021, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.xinnuo.account

import android.accounts.AbstractAccountAuthenticator
import android.accounts.Account
import android.accounts.AccountAuthenticatorResponse
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.IBinder

/**
 * 描 述：
 *      清单配置：
 *      <!-- 用于账户同步拉活 -->
 *      <service
 *         android:name=".account.AuthenticationService"
 *         android:enabled="true"
 *         android:exported="true">
 *           <intent-filter>
 *              <action android:name="android.accounts.AccountAuthenticator" />
 *           </intent-filter>

 *           <meta-data
 *              android:name="android.accounts.AccountAuthenticator"
 *              android:resource="@xml/account_authenticator" />
 *       </service>
 *
 * 作 者：小卷毛  2021-09-10 11:01
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
class AuthenticationService : Service() {

    /**
     * 账户验证器
     */
    private lateinit var mAccountAuthenticator: AccountAuthenticator

    override fun onBind(intent: Intent?): IBinder? = mAccountAuthenticator.iBinder

    override fun onCreate() {
        super.onCreate()

        // 创建账户验证器
        mAccountAuthenticator = AccountAuthenticator(this)
    }

    /**
     * 账户验证器
     */
    inner class AccountAuthenticator(context: Context) : AbstractAccountAuthenticator(context) {

        override fun editProperties(
            response: AccountAuthenticatorResponse?,
            accountType: String?
        ) = null

        override fun addAccount(
            response: AccountAuthenticatorResponse?,
            accountType: String?,
            authTokenType: String?,
            requiredFeatures: Array<out String>?,
            options: Bundle?
        ) = null

        override fun confirmCredentials(
            response: AccountAuthenticatorResponse?,
            account: Account?,
            options: Bundle?
        ) = null

        override fun getAuthToken(
            response: AccountAuthenticatorResponse?,
            account: Account?,
            authTokenType: String?,
            options: Bundle?
        ) = null

        override fun getAuthTokenLabel(authTokenType: String?) = null

        override fun updateCredentials(
            response: AccountAuthenticatorResponse?,
            account: Account?,
            authTokenType: String?,
            options: Bundle?
        ) = null

        override fun hasFeatures(
            response: AccountAuthenticatorResponse?,
            account: Account?,
            features: Array<out String>?
        ) = null

    }

}